import {observable, action} from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import {LoadHoc, loading} from '../hoc/loadHoc';

export default class SignStore extends LoadHoc {
  /**
   * 获取用户签到记录
   */
  @observable userSignRecord: api.YNJWTSignVOSignViewVO = {};

  @loading @action
  async getUserSignRecord(params: {
    callback?: (res: api.YNJWTSignVOSignViewVO) => void;
  }) {
    const {callback} = params;
    const userSignRecord = await request(api.AppsignApiFetchParamCreactor.appsignGetUserSignRecordAsync({}));
    this.userSignRecord = userSignRecord;
    callback && callback(userSignRecord);
  }

  /**
   * 签到
   */
  @loading @action
  async sign(params: {
    callback?: (res) => void;
  }) {
    const {callback} = params;
    const res = await request(api.AppsignApiFetchParamCreactor.appsignSignAsync({}));
    callback && callback(res);
  }

  /**
   * 获取用户签到文章
   */
  @observable signedArticle: api.YNJWTSignVOSignedArticleVO = {};

  @loading @action
  async getSignedArticle(params: {
    callback?: (res: api.YNJWTSignVOSignedArticleVO) => void;
  }) {
    const {callback} = params;
    const signedArticle = await request(api.AppsignApiFetchParamCreactor.appsignGetSignedArticleAsync({}));
    this.signedArticle = signedArticle;
    callback && callback(signedArticle);
  }
}
